using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace UI.UserControl
{
    public class CssLableITemplate : ITemplate
    {
        protected string colname;
        protected string m_css;
        public CssLableITemplate(string cname)
        {
            colname = cname;
            m_css = "";
        }
        public CssLableITemplate(string cname, string css)
        {
            colname = cname;
            m_css = css;
        }

        public virtual void InstantiateIn(Control container)
        {
            Label control = new Label();
            if(m_css != "" && m_css!=null)
            {
                control.CssClass = m_css;
            }

            control.ID = "lbl_" + colname;
            control.DataBinding += new EventHandler(this.OnDataBinding);

            container.Controls.Add(control);
        }

        public virtual void OnDataBinding(object sender, EventArgs e)
        {
            Label control = (Label)sender;
            
            DataGridItem container = (DataGridItem)control.NamingContainer;

            string value = ((DataRowView)container.DataItem)[colname].ToString();

            //control.Width = Unit.Parse("98%");
            control.Text = value;

            if (m_css != "" && m_css != null)
            {
                control.ToolTip = value;
            }
            //control.Style.Add(HtmlTextWriterStyle.Overflow, "hidden");
            //control.Style.Add(HtmlTextWriterStyle.TextOverflow, "ellipsis");
            //control.Style.Add(HtmlTextWriterStyle.WhiteSpace, "nowrap");

        }      
    }
}
